home *** CD-ROM | disk | FTP | other *** search
- Path: dash.com!news
- From: Jim Bosshardt <jbossha@dash.com>
- Newsgroups: comp.lang.c
- Subject: Newbie needs help w/ recursion
- Date: 18 Mar 1996 23:04:57 GMT
- Organization: Shaman Exchange
- Message-ID: <4ikq6p$io1@impsets.dash.com>
- NNTP-Posting-Host: 198.199.231.42
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (Macintosh; I; 68K)
- X-URL: news:comp.lang.c
-
- Hi, I am new and am about to pull my hair out over the supposedly simple
- recursion problem I have. The function is to take a number and raise it
- to a neg or pos power and return the value to main(). I need to take
- the following and make it a recursive function...
-
- double power (double a, float b)
- {
- double power = 1;
- int i;
-
- if (a == 0)
- pow = 0;
- else if (b == 0)
- pow = 1;
- else if Ib > 0)
- {
- for(i = 1; i <= b; i++)
- pow *= a;
- }
- else if (b < 0)
- {
- b = -b;
- for (i = 1; i <= b; i+)
- pow *= a;
- return 1/pow;
- }
- return pow;
- }
-
- I can only find recursion examples that deal with factorials and cannot
- seem to get the function to be recursive. I have struggled with this
- for days and would really appreciate any help any body can give me.
- Thanks!
-
- Dianna Bosshardt
-
-
-